<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>fielddescriptor.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_proto2_fielddescriptor.js.html">fielddescriptor.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2008 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Protocol Buffer Field Descriptor class.
<a name="line17"></a> */
<a name="line18"></a>
<a name="line19"></a>goog.provide(&#39;goog.proto2.FieldDescriptor&#39;);
<a name="line20"></a>
<a name="line21"></a>goog.require(&#39;goog.proto2.Util&#39;);
<a name="line22"></a>goog.require(&#39;goog.string&#39;);
<a name="line23"></a>
<a name="line24"></a>
<a name="line25"></a>/**
<a name="line26"></a> * A class which describes a field in a Protocol Buffer 2 Message.
<a name="line27"></a> *
<a name="line28"></a> * @param {Function} messageType Constructor for the message
<a name="line29"></a> *     class to which the field described by this class belongs.
<a name="line30"></a> * @param {number|string} tag The field&#39;s tag index.
<a name="line31"></a> * @param {Object} metadata The metadata about this field that will be used
<a name="line32"></a> *     to construct this descriptor.
<a name="line33"></a> *
<a name="line34"></a> * @constructor
<a name="line35"></a> */
<a name="line36"></a>goog.proto2.FieldDescriptor = function(messageType, tag, metadata) {
<a name="line37"></a>  /**
<a name="line38"></a>   * The message type that contains the field that this
<a name="line39"></a>   * descriptor describes.
<a name="line40"></a>   * @type {Function}
<a name="line41"></a>   * @private
<a name="line42"></a>   */
<a name="line43"></a>  this.parent_ = messageType;
<a name="line44"></a>
<a name="line45"></a>  // Ensure that the tag is numeric.
<a name="line46"></a>  goog.proto2.Util.assert(goog.string.isNumeric(tag));
<a name="line47"></a>
<a name="line48"></a>  /**
<a name="line49"></a>   * The field&#39;s tag number.
<a name="line50"></a>   * @type {number}
<a name="line51"></a>   * @private
<a name="line52"></a>   */
<a name="line53"></a>  this.tag_ = /** @type {number} */ (tag);
<a name="line54"></a>
<a name="line55"></a>  /**
<a name="line56"></a>   * The field&#39;s name.
<a name="line57"></a>   * @type {string}
<a name="line58"></a>   * @private
<a name="line59"></a>   */
<a name="line60"></a>  this.name_ = metadata.name;
<a name="line61"></a>
<a name="line62"></a>  /**
<a name="line63"></a>   * If true, this field is a repeating field.
<a name="line64"></a>   * @type {boolean}
<a name="line65"></a>   * @private
<a name="line66"></a>   */
<a name="line67"></a>  this.isRepeated_ = !!metadata.repeated;
<a name="line68"></a>
<a name="line69"></a>  /**
<a name="line70"></a>   * If true, this field is required.
<a name="line71"></a>   * @type {boolean}
<a name="line72"></a>   * @private
<a name="line73"></a>   */
<a name="line74"></a>  this.isRequired_ = !!metadata.required;
<a name="line75"></a>
<a name="line76"></a>  /**
<a name="line77"></a>   * The field type of this field.
<a name="line78"></a>   * @type {goog.proto2.Message.FieldType}
<a name="line79"></a>   * @private
<a name="line80"></a>   */
<a name="line81"></a>  this.fieldType_ = metadata.fieldType;
<a name="line82"></a>
<a name="line83"></a>  /**
<a name="line84"></a>   * If this field is a primitive: The native (ECMAScript) type of this field.
<a name="line85"></a>   * If an enumeration: The enumeration object.
<a name="line86"></a>   * If a message or group field: The Message function.
<a name="line87"></a>   * @type {Object}
<a name="line88"></a>   * @private
<a name="line89"></a>   */
<a name="line90"></a>  this.nativeType_ = metadata.type;
<a name="line91"></a>
<a name="line92"></a>  /**
<a name="line93"></a>   * The default value of this field, if different from the default, default
<a name="line94"></a>   * value.
<a name="line95"></a>   * @type {Object|undefined}
<a name="line96"></a>   * @private
<a name="line97"></a>   */
<a name="line98"></a>  this.defaultValue_ = metadata.defaultValue;
<a name="line99"></a>};
<a name="line100"></a>
<a name="line101"></a>
<a name="line102"></a>/**
<a name="line103"></a> * Returns the tag of the field that this descriptor represents.
<a name="line104"></a> *
<a name="line105"></a> * @return {number} The tag number.
<a name="line106"></a> */
<a name="line107"></a>goog.proto2.FieldDescriptor.prototype.getTag = function() {
<a name="line108"></a>  return this.tag_;
<a name="line109"></a>};
<a name="line110"></a>
<a name="line111"></a>
<a name="line112"></a>/**
<a name="line113"></a> * Returns the descriptor describing the message that defined this field.
<a name="line114"></a> * @return {goog.proto2.Descriptor} The descriptor.
<a name="line115"></a> */
<a name="line116"></a>goog.proto2.FieldDescriptor.prototype.getContainingType = function() {
<a name="line117"></a>  return this.parent_.descriptor_;
<a name="line118"></a>};
<a name="line119"></a>
<a name="line120"></a>
<a name="line121"></a>/**
<a name="line122"></a> * Returns the name of the field that this descriptor represents.
<a name="line123"></a> * @return {String} The name.
<a name="line124"></a> */
<a name="line125"></a>goog.proto2.FieldDescriptor.prototype.getName = function() {
<a name="line126"></a>  return this.name_;
<a name="line127"></a>};
<a name="line128"></a>
<a name="line129"></a>
<a name="line130"></a>/**
<a name="line131"></a> * Returns the default value of this field.
<a name="line132"></a> * @return {Object} The default value.
<a name="line133"></a> */
<a name="line134"></a>goog.proto2.FieldDescriptor.prototype.getDefaultValue = function() {
<a name="line135"></a>  if (this.defaultValue_ === undefined) {
<a name="line136"></a>    // Set the default value based on a new instance of the native type.
<a name="line137"></a>    // This will be (0, false, &quot;&quot;) for (number, boolean, string) and will
<a name="line138"></a>    // be a new instance of a group/message if the field is a message type.
<a name="line139"></a>    this.defaultValue_ = new this.nativeType_;
<a name="line140"></a>  }
<a name="line141"></a>
<a name="line142"></a>  return /** @type {Object} */ (this.defaultValue_);
<a name="line143"></a>};
<a name="line144"></a>
<a name="line145"></a>
<a name="line146"></a>/**
<a name="line147"></a> * Returns the field type of the field described by this descriptor.
<a name="line148"></a> * @return {goog.proto2.Message.FieldType} The field type.
<a name="line149"></a> */
<a name="line150"></a>goog.proto2.FieldDescriptor.prototype.getFieldType = function() {
<a name="line151"></a>  return this.fieldType_;
<a name="line152"></a>};
<a name="line153"></a>
<a name="line154"></a>
<a name="line155"></a>/**
<a name="line156"></a> * Returns the native (i.e. ECMAScript) type of the field described by this
<a name="line157"></a> * descriptor.
<a name="line158"></a> *
<a name="line159"></a> * @return {Object} The native type.
<a name="line160"></a> */
<a name="line161"></a>goog.proto2.FieldDescriptor.prototype.getNativeType = function() {
<a name="line162"></a>  return this.nativeType_;
<a name="line163"></a>};
<a name="line164"></a>
<a name="line165"></a>
<a name="line166"></a>/**
<a name="line167"></a> * Returns the descriptor of the message type of this field. Only valid
<a name="line168"></a> * for fields of type GROUP and MESSAGE.
<a name="line169"></a> *
<a name="line170"></a> * @return {goog.proto2.Descriptor} The message descriptor.
<a name="line171"></a> */
<a name="line172"></a>goog.proto2.FieldDescriptor.prototype.getFieldMessageType = function() {
<a name="line173"></a>  goog.proto2.Util.assert(
<a name="line174"></a>      this.fieldType_ == goog.proto2.Message.FieldType.MESSAGE ||
<a name="line175"></a>      this.fieldType_ == goog.proto2.Message.FieldType.GROUP,
<a name="line176"></a>      &#39;Expected message or group&#39;);
<a name="line177"></a>
<a name="line178"></a>  return this.nativeType_.descriptor_;
<a name="line179"></a>};
<a name="line180"></a>
<a name="line181"></a>
<a name="line182"></a>/**
<a name="line183"></a> * Returns whether the field described by this descriptor is repeating.
<a name="line184"></a> * @return {Boolean} Whether the field is repeated.
<a name="line185"></a> */
<a name="line186"></a>goog.proto2.FieldDescriptor.prototype.isRepeated = function() {
<a name="line187"></a>  return this.isRepeated_;
<a name="line188"></a>};
<a name="line189"></a>
<a name="line190"></a>
<a name="line191"></a>/**
<a name="line192"></a> * Returns whether the field described by this descriptor is required.
<a name="line193"></a> * @return {Boolean} Whether the field is required.
<a name="line194"></a> */
<a name="line195"></a>goog.proto2.FieldDescriptor.prototype.isRequired = function() {
<a name="line196"></a>  return this.isRequired_;
<a name="line197"></a>};
<a name="line198"></a>
<a name="line199"></a>
<a name="line200"></a>/**
<a name="line201"></a> * Returns whether the field described by this descriptor is optional.
<a name="line202"></a> * @return {Boolean} Whether the field is optional.
<a name="line203"></a> */
<a name="line204"></a>goog.proto2.FieldDescriptor.prototype.isOptional = function() {
<a name="line205"></a>  return !this.isRepeated_ &amp;&amp; !this.isRequired_;
<a name="line206"></a>};
</pre>


</body>
</html>
